package com.gems.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.hibernate.Query;
import org.hibernate.Session;

import com.gems.model.Stock;
import com.gems.util.HibernateUtil;

@Path("/stocks")
public class GemsService {

	private Session session;

	@GET
	@Path("/json")
	@Produces(MediaType.APPLICATION_JSON)
	public List getGemsJSON() {
		session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		Query query = session.createQuery("from Stock");
		//query.setParameter("id", 1);
		List result = query.list();
		session.getTransaction().commit();
		session.close();
		return result;
	}
	
	@GET
	@Path("/xml")
	@Produces(MediaType.APPLICATION_XML)
	public List<Stock> getGemsXML() {
		session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		Query query = session.createQuery("from Stock");
		//query.setParameter("id", 1);
		List result = query.list();
		session.getTransaction().commit();
		session.close();
		return result;
	}
	
}
